<?php
namespace common\modules\content\frontend\controllers;

use common\modules\content\models\Page;
use Yii;
use yii\web\Controller;
use yii\web\NotFoundHttpException;

class PageController extends Controller
{

    public function actionView($slug)
    {
        $model = Page::find()->where([
            'slug' => $slug,
            'status' => Page::STATUS_PUBLISHED
        ])->one();
        if (! $model) {
            throw new NotFoundHttpException(Yii::t('frontend', 'Page not found'));
        }
        
        $viewFile = $model->view ?  : 'view';
        return $this->render($viewFile, [
            'model' => $model
        ]);
    }
}
